package model

import (
	"fmt"
	"gorm.io/gorm"
	"time"
)

type _WkbCustomerServiceMgr struct {
	*_BaseMgr
}

// WkbCustomerServiceMgr open func
func WkbCustomerServiceMgr(db *gorm.DB) *_WkbCustomerServiceMgr {
	if db == nil {
		panic(fmt.Errorf("WkbCustomerServiceMgr need init by db"))
	}
	ctx, cancel := context.WithCancel(context.Background())
	return &_WkbCustomerServiceMgr{_BaseMgr: &_BaseMgr{DB: db.Table("wkb_customer_service"), isRelated: globalIsRelated, ctx: ctx, cancel: cancel, timeout: -1}}
}

// GetTableName get sql table name.获取数据库名字
func (obj *_WkbCustomerServiceMgr) GetTableName() string {
	return "wkb_customer_service"
}

// Get 获取
func (obj *_WkbCustomerServiceMgr) Get() (result WkbCustomerService, err error) {
	err = obj.DB.WithContext(obj.ctx).Table(obj.GetTableName()).Find(&result).Error

	return
}

// Gets 获取批量结果
func (obj *_WkbCustomerServiceMgr) Gets() (results []*WkbCustomerService, err error) {
	err = obj.DB.WithContext(obj.ctx).Table(obj.GetTableName()).Find(&results).Error

	return
}

//////////////////////////option case ////////////////////////////////////////////

// WithID id获取 自增id
func (obj *_WkbCustomerServiceMgr) WithID(id int) Option {
	return optionFunc(func(o *options) { o.query["id"] = id })
}

// WithAuthID auth_id获取 wkb_realname_auth的主键id
func (obj *_WkbCustomerServiceMgr) WithAuthID(authID int) Option {
	return optionFunc(func(o *options) { o.query["auth_id"] = authID })
}

// WithRealname realname获取 真实姓名(冗余)
func (obj *_WkbCustomerServiceMgr) WithRealname(realname string) Option {
	return optionFunc(func(o *options) { o.query["realname"] = realname })
}

// WithIsManage is_manage获取 是否管理员:1=是,2=否
func (obj *_WkbCustomerServiceMgr) WithIsManage(isManage int8) Option {
	return optionFunc(func(o *options) { o.query["is_manage"] = isManage })
}

// WithSeeCustomerService see_customer_service获取 查看其他客服权限:1=有,2=否
func (obj *_WkbCustomerServiceMgr) WithSeeCustomerService(seeCustomerService int8) Option {
	return optionFunc(func(o *options) { o.query["see_customer_service"] = seeCustomerService })
}

// WithSeeCustomer see_customer获取 查看用户权限:1=可见管理员,2=可见同技能组,3=所有可见
func (obj *_WkbCustomerServiceMgr) WithSeeCustomer(seeCustomer int8) Option {
	return optionFunc(func(o *options) { o.query["see_customer"] = seeCustomer })
}

// WithDeleted deleted获取 是否删除:1=删除,2=否
func (obj *_WkbCustomerServiceMgr) WithDeleted(deleted int8) Option {
	return optionFunc(func(o *options) { o.query["deleted"] = deleted })
}

// WithUpdatedAt updated_at获取 更新时间
func (obj *_WkbCustomerServiceMgr) WithUpdatedAt(updatedAt time.Time) Option {
	return optionFunc(func(o *options) { o.query["updated_at"] = updatedAt })
}

// WithCreatedAt created_at获取 创建时间
func (obj *_WkbCustomerServiceMgr) WithCreatedAt(createdAt time.Time) Option {
	return optionFunc(func(o *options) { o.query["created_at"] = createdAt })
}

// GetByOption 功能选项模式获取
func (obj *_WkbCustomerServiceMgr) GetByOption(opts ...Option) (result WkbCustomerService, err error) {
	options := options{
		query: make(map[string]interface{}, len(opts)),
	}
	for _, o := range opts {
		o.apply(&options)
	}

	err = obj.DB.WithContext(obj.ctx).Table(obj.GetTableName()).Where(options.query).Find(&result).Error

	return
}

// GetByOptions 批量功能选项模式获取
func (obj *_WkbCustomerServiceMgr) GetByOptions(opts ...Option) (results []*WkbCustomerService, err error) {
	options := options{
		query: make(map[string]interface{}, len(opts)),
	}
	for _, o := range opts {
		o.apply(&options)
	}

	err = obj.DB.WithContext(obj.ctx).Table(obj.GetTableName()).Where(options.query).Find(&results).Error

	return
}

//////////////////////////enume case ////////////////////////////////////////////

// GetFromID 通过id获取内容 自增id
func (obj *_WkbCustomerServiceMgr) GetFromID(id int) (result WkbCustomerService, err error) {
	err = obj.DB.WithContext(obj.ctx).Table(obj.GetTableName()).Where("id = ?", id).Find(&result).Error

	return
}

// GetBatchFromID 批量唯一主键查找 自增id
func (obj *_WkbCustomerServiceMgr) GetBatchFromID(ids []int) (results []*WkbCustomerService, err error) {
	err = obj.DB.WithContext(obj.ctx).Table(obj.GetTableName()).Where("id IN (?)", ids).Find(&results).Error

	return
}

// GetFromAuthID 通过auth_id获取内容 wkb_realname_auth的主键id
func (obj *_WkbCustomerServiceMgr) GetFromAuthID(authID int) (results []*WkbCustomerService, err error) {
	err = obj.DB.WithContext(obj.ctx).Table(obj.GetTableName()).Where("auth_id = ?", authID).Find(&results).Error

	return
}

// GetBatchFromAuthID 批量唯一主键查找 wkb_realname_auth的主键id
func (obj *_WkbCustomerServiceMgr) GetBatchFromAuthID(authIDs []int) (results []*WkbCustomerService, err error) {
	err = obj.DB.WithContext(obj.ctx).Table(obj.GetTableName()).Where("auth_id IN (?)", authIDs).Find(&results).Error

	return
}

// GetFromRealname 通过realname获取内容 真实姓名(冗余)
func (obj *_WkbCustomerServiceMgr) GetFromRealname(realname string) (results []*WkbCustomerService, err error) {
	err = obj.DB.WithContext(obj.ctx).Table(obj.GetTableName()).Where("realname = ?", realname).Find(&results).Error

	return
}

// GetBatchFromRealname 批量唯一主键查找 真实姓名(冗余)
func (obj *_WkbCustomerServiceMgr) GetBatchFromRealname(realnames []string) (results []*WkbCustomerService, err error) {
	err = obj.DB.WithContext(obj.ctx).Table(obj.GetTableName()).Where("realname IN (?)", realnames).Find(&results).Error

	return
}

// GetFromIsManage 通过is_manage获取内容 是否管理员:1=是,2=否
func (obj *_WkbCustomerServiceMgr) GetFromIsManage(isManage int8) (results []*WkbCustomerService, err error) {
	err = obj.DB.WithContext(obj.ctx).Table(obj.GetTableName()).Where("is_manage = ?", isManage).Find(&results).Error

	return
}

// GetBatchFromIsManage 批量唯一主键查找 是否管理员:1=是,2=否
func (obj *_WkbCustomerServiceMgr) GetBatchFromIsManage(isManages []int8) (results []*WkbCustomerService, err error) {
	err = obj.DB.WithContext(obj.ctx).Table(obj.GetTableName()).Where("is_manage IN (?)", isManages).Find(&results).Error

	return
}

// GetFromSeeCustomerService 通过see_customer_service获取内容 查看其他客服权限:1=有,2=否
func (obj *_WkbCustomerServiceMgr) GetFromSeeCustomerService(seeCustomerService int8) (results []*WkbCustomerService, err error) {
	err = obj.DB.WithContext(obj.ctx).Table(obj.GetTableName()).Where("see_customer_service = ?", seeCustomerService).Find(&results).Error

	return
}

// GetBatchFromSeeCustomerService 批量唯一主键查找 查看其他客服权限:1=有,2=否
func (obj *_WkbCustomerServiceMgr) GetBatchFromSeeCustomerService(seeCustomerServices []int8) (results []*WkbCustomerService, err error) {
	err = obj.DB.WithContext(obj.ctx).Table(obj.GetTableName()).Where("see_customer_service IN (?)", seeCustomerServices).Find(&results).Error

	return
}

// GetFromSeeCustomer 通过see_customer获取内容 查看用户权限:1=可见管理员,2=可见同技能组,3=所有可见
func (obj *_WkbCustomerServiceMgr) GetFromSeeCustomer(seeCustomer int8) (results []*WkbCustomerService, err error) {
	err = obj.DB.WithContext(obj.ctx).Table(obj.GetTableName()).Where("see_customer = ?", seeCustomer).Find(&results).Error

	return
}

// GetBatchFromSeeCustomer 批量唯一主键查找 查看用户权限:1=可见管理员,2=可见同技能组,3=所有可见
func (obj *_WkbCustomerServiceMgr) GetBatchFromSeeCustomer(seeCustomers []int8) (results []*WkbCustomerService, err error) {
	err = obj.DB.WithContext(obj.ctx).Table(obj.GetTableName()).Where("see_customer IN (?)", seeCustomers).Find(&results).Error

	return
}

// GetFromDeleted 通过deleted获取内容 是否删除:1=删除,2=否
func (obj *_WkbCustomerServiceMgr) GetFromDeleted(deleted int8) (results []*WkbCustomerService, err error) {
	err = obj.DB.WithContext(obj.ctx).Table(obj.GetTableName()).Where("deleted = ?", deleted).Find(&results).Error

	return
}

// GetBatchFromDeleted 批量唯一主键查找 是否删除:1=删除,2=否
func (obj *_WkbCustomerServiceMgr) GetBatchFromDeleted(deleteds []int8) (results []*WkbCustomerService, err error) {
	err = obj.DB.WithContext(obj.ctx).Table(obj.GetTableName()).Where("deleted IN (?)", deleteds).Find(&results).Error

	return
}

// GetFromUpdatedAt 通过updated_at获取内容 更新时间
func (obj *_WkbCustomerServiceMgr) GetFromUpdatedAt(updatedAt time.Time) (results []*WkbCustomerService, err error) {
	err = obj.DB.WithContext(obj.ctx).Table(obj.GetTableName()).Where("updated_at = ?", updatedAt).Find(&results).Error

	return
}

// GetBatchFromUpdatedAt 批量唯一主键查找 更新时间
func (obj *_WkbCustomerServiceMgr) GetBatchFromUpdatedAt(updatedAts []time.Time) (results []*WkbCustomerService, err error) {
	err = obj.DB.WithContext(obj.ctx).Table(obj.GetTableName()).Where("updated_at IN (?)", updatedAts).Find(&results).Error

	return
}

// GetFromCreatedAt 通过created_at获取内容 创建时间
func (obj *_WkbCustomerServiceMgr) GetFromCreatedAt(createdAt time.Time) (results []*WkbCustomerService, err error) {
	err = obj.DB.WithContext(obj.ctx).Table(obj.GetTableName()).Where("created_at = ?", createdAt).Find(&results).Error

	return
}

// GetBatchFromCreatedAt 批量唯一主键查找 创建时间
func (obj *_WkbCustomerServiceMgr) GetBatchFromCreatedAt(createdAts []time.Time) (results []*WkbCustomerService, err error) {
	err = obj.DB.WithContext(obj.ctx).Table(obj.GetTableName()).Where("created_at IN (?)", createdAts).Find(&results).Error

	return
}

//////////////////////////primary index case ////////////////////////////////////////////

// FetchByPrimaryKey primay or index 获取唯一内容
func (obj *_WkbCustomerServiceMgr) FetchByPrimaryKey(id int) (result WkbCustomerService, err error) {
	err = obj.DB.WithContext(obj.ctx).Table(obj.GetTableName()).Where("id = ?", id).Find(&result).Error

	return
}
